package com.gxa.modules.sys.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.gxa.common.utils.PageUtils;
import com.gxa.common.utils.Result;
import com.gxa.modules.sys.dto.ComboDto;
import com.gxa.modules.sys.dto.MyOrderDto;
import com.gxa.modules.sys.dto.OrderManagementDto;
import com.gxa.modules.sys.service.MyOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Api(tags = "订单接口")
@RestController
public class MyOrderController {

    @Autowired
    private MyOrderService myorderService;

    @ApiOperation(value = "订单--查询接口")
    /*@ApiImplicitParams({
            @ApiImplicitParam(paramType = "query",name = "page",value ="当前是第几页",dataType ="int"),
            @ApiImplicitParam(paramType = "query",name = "limit",value ="每页显示多少条",dataType ="int"),
            @ApiImplicitParam(paramType = "query",name = "createTime",value ="查询条件：下单时间",dataType ="Date"),
            @ApiImplicitParam(paramType = "query",name = "no",value ="查询条件：订单号",dataType ="int"),
            @ApiImplicitParam(paramType = "query",name = "stata",value ="查询条件：订单状态",dataType ="int"),
            @ApiImplicitParam(paramType = "query",name = "areaName",value ="查询条件：卡卷名称",dataType ="String"),
            @ApiImplicitParam(paramType = "query",name = "num",value ="查询条件：桌子号码",dataType ="String"),
            @ApiImplicitParam(paramType = "query",name = "tel",value ="查询条件：电话号码",dataType ="String"),
            @ApiImplicitParam(paramType = "query",name = "order",value ="升序asc，降序填desc",dataType ="String"),
            @ApiImplicitParam(paramType = "query",name = "sidx",value ="排序字段",dataType ="String"),

    })*/
    @PostMapping("/myorder/list")
    public Result queryList(@RequestBody OrderManagementDto orderManagementDto){

        Page<Map<String,Object>> pageHelperList = PageHelper.startPage(orderManagementDto.getPage(),orderManagementDto.getLimit());
        List<OrderManagementDto> orderManagementDtos = this.myorderService.queryByPage(orderManagementDto);
        Map map = new HashMap();
        map.put("myorder",orderManagementDtos);
        map.put("count",pageHelperList.getTotal());

        return new Result().ok(map);
    }

    @ApiOperation(value = "修改订单状态接口")
    @PutMapping("/update/MyOrder")
    public Result updateMyOrder(@RequestBody MyOrderDto myOrderDto) {
        try {
            this.myorderService.updateState(myOrderDto);
            return new Result().ok();
        } catch (Exception e) {
            return new Result().error("修改失败");
        }
    }

    @ApiOperation(value = "我的订单查询接口")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query",required = true,name = "userId",value ="用户id",dataType ="int"),
            @ApiImplicitParam(paramType = "query",name = "state",value ="订单状态",dataType ="int"),
            @ApiImplicitParam(paramType = "query",name = "sortord",value ="排序字段",dataType ="int"),
    })
    @GetMapping("/myorder/myorderList")
    public Result queryMyOrderList(@RequestParam @ApiIgnore Map<String,Object> params){

        List<OrderManagementDto> orderManagementDtos = this.myorderService.queryMyOrderList(params);

        return new Result<>().ok(orderManagementDtos);
    }

}
